﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class frmHoaDonBanVe : Form
    {
        public frmHoaDonBanVe()
        {
            InitializeComponent();
        }

        private void frmHoaDonBanVe_Load(object sender, EventArgs e)
        {
            try
            {
                HoaDonBanVeBUS hdbv = new HoaDonBanVeBUS();
                List<HoaDonBanVeDTO> dshdbv = new List<HoaDonBanVeDTO>();
                dshdbv = hdbv.LayDanhSachHoaDonbanVe();
                int stt = 1;
                for (int i = 0; i < dshdbv.Count; i++)
                {
                    dgvDanhSachDDH.Rows.Add(stt, dshdbv[i].MaHD, dshdbv[i].NgayLap, dshdbv[i].TongTien, dshdbv[i].GiamGia, dshdbv[i].MaKH, dshdbv[i].TenKH);
                    stt++;
                }    

            }
			
            catch (Exception ex)
            {

                MessageBox.Show("Lỗi:" + ex.ToString());
            }
        }

        private void dgvChiTietDDH_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        public void hienthichitiet_PXK(int ma)
        {
            CT_HoaDonBanVeBUS cthdbv = new CT_HoaDonBanVeBUS();
            List<CT_HoaDonBanVeDTO> dscthdbv = new List<CT_HoaDonBanVeDTO>();
            
            dscthdbv = cthdbv.LayDanhSachHoaDonBanVeTheoMa(ma);


            int stt = 1;
            for (int i = 0; i < dscthdbv.Count; i++)
            {

                dgvChiTietDDH.Rows.Add(stt, dscthdbv[i].MaHD, dscthdbv[i].MaLoai, dscthdbv[i].TenLoai, dscthdbv[i].SoLuong, dscthdbv[i].Gia);
                stt++;
            }

        }

        private void dgvDanhSachDDH_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            int intIndex = e.RowIndex;

            dgvDanhSachDDH.Rows[intIndex].Selected = true;



            try
            {
                dgvChiTietDDH.Rows.Clear();
                int ma = int.Parse(dgvDanhSachDDH.Rows[e.RowIndex].Cells[1].Value.ToString());
                hienthichitiet_PXK(ma);
            }
            catch (Exception)
            {

                return;
            }
         
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frmThemHoaDonBanVe fr = new frmThemHoaDonBanVe();
            fr.ShowDialog();
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            
        }

        private void panelEx1_Click(object sender, EventArgs e)
        {

        }
    }
}
